<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class RFF::OutputReader - RDoc Documentation</title>

<link href="../fonts.css" rel="stylesheet">
<link href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script src="../js/jquery.js"></script>
<script src="../js/navigation.js"></script>
<script src="../js/search_index.js"></script>
<script src="../js/search.js"></script>
<script src="../js/searcher.js"></script>
<script src="../js/darkfish.js"></script>


<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    <div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  
  <p class="link">Object
  
</div>

    
    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-new">::new</a>
    
    <li ><a href="#method-i-get_raw_buffer">#get_raw_buffer</a>
    
    <li ><a href="#method-i-gets">#gets</a>
    
    <li ><a href="#method-i-join_reading_thread">#join_reading_thread</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-RFF::OutputReader">
  <h1 id="class-RFF::OutputReader" class="class">
    class RFF::OutputReader
  </h1>

  <section class="description">
    
<p>A class that reads the given IO stream and provides advanced reading
functions for it. It reads the given stream to the internal buffer in
separate thread and uses this buffer to provide reading functionality that
is not available in IO stream alone</p>

  </section>

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">(io)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This constructor initializes the class instance with IO stream and starts
the stream reading thread</p>
<ul><li>
<p><em>io</em> - the IO stream to read from</p>
</li></ul>
          
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/output_reader.rb, line 10</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">io</span>
  <span class="ruby-ivar">@buffer</span> = <span class="ruby-string">&quot;&quot;</span>
  <span class="ruby-ivar">@writecount</span> = <span class="ruby-value">0</span>
  <span class="ruby-ivar">@readcount</span> = <span class="ruby-value">0</span>
  <span class="ruby-ivar">@eof</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-ivar">@reading_thread</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">th</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">while</span> <span class="ruby-identifier">data</span> = <span class="ruby-identifier">io</span>.<span class="ruby-identifier">read</span>(<span class="ruby-value">10</span>)
      <span class="ruby-ivar">@buffer</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">data</span>
      <span class="ruby-ivar">@writecount</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">length</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@eof</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-get_raw_buffer" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_raw_buffer</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method outputs the internal buffer without any additional processing</p>
          
          

          
          <div class="method-source-code" id="get_raw_buffer-source">
            <pre><span class="ruby-comment"># File lib/output_reader.rb, line 57</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_raw_buffer</span>
  <span class="ruby-ivar">@buffer</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-gets" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">gets</span><span
            class="method-args">(seps=["\n"])</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method provides an implementation of IO gets method for streams
containing lines with different line separators in some parts</p>
<ul><li>
<p><em>seps</em> - an array defining the line separators. Defaults to one,
default LF separator</p>
</li></ul>

<p>Outputs next line from the stream or “EOF\n” when the stream reaches its
end</p>
          
          

          
          <div class="method-source-code" id="gets-source">
            <pre><span class="ruby-comment"># File lib/output_reader.rb, line 28</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">gets</span> <span class="ruby-identifier">seps</span>=[<span class="ruby-string">&quot;\n&quot;</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@writecount</span> <span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@readcount</span>
    <span class="ruby-identifier">line</span> = <span class="ruby-string">&quot;&quot;</span>
    <span class="ruby-keyword">begin</span>
      <span class="ruby-identifier">c</span> = <span class="ruby-ivar">@buffer</span>[<span class="ruby-ivar">@readcount</span>]
      <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">c</span>.<span class="ruby-identifier">nil?</span>
        <span class="ruby-ivar">@readcount</span> = <span class="ruby-ivar">@readcount</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>
        <span class="ruby-identifier">line</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">c</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">seps</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">c</span>)
          <span class="ruby-keyword">break</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span> <span class="ruby-keyword">while</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@eof</span>
    <span class="ruby-identifier">line</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-ivar">@eof</span>
    <span class="ruby-string">&quot;EOF\n&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-join_reading_thread" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">join_reading_thread</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This method can be used to join the reading thread in some place of the
script</p>
          
          

          
          <div class="method-source-code" id="join_reading_thread-source">
            <pre><span class="ruby-comment"># File lib/output_reader.rb, line 51</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">join_reading_thread</span>
  <span class="ruby-ivar">@reading_thread</span>.<span class="ruby-identifier">join</span> 
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.0.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>

